<?php

if(!defined('EXECROOT')) {
	define('EXECROOT','');
}

class lcars {

	static $w = null;
	static $forceRegen = false;
	static $redAlert = false;
	
	static $sndsrcTimeout = array('klaxon' => null);
	static $sndsrc = array(0 => null, 1 => null, 'klaxon' => null);
	static $sndsrccur = 0;
	static $snd = array();

	const TTF = '/usr/share/commnet/ui/lcars.ttf';
	const UI_DIR = '/usr/share/commnet/ui';
	const UI_CACHE_DIR = '/var/cache/commnet';
	const SND_DIR = '/usr/share/commnet/snd';
	
	const SND_INIT_CMD = 'initialize-command.wav';
	const SND_INIT_DEFAULT = 'default-beep.wav';
	const SND_INIT_SCROLL = 'scroll.wav';
	const SND_SCROLL_JMP = 'scroll-jump.wav';
	const SND_CHAN_OPEN = 'channel-open.wav';
	const SND_CHAN_CLOSE = 'channel-close.wav';
	const SND_INIT_REMOTE = 'remote-init.wav';
	
	const DATEFMT = 'YmdHis';
	
	static function date() {
		return date('YmdHis');
	}

	static function mkUIFilename($what) {
		return preg_replace('/[^a-zA-Z0-9-_\.]/','',$what);
	}
	
	static function killTime() {
		while(Gtk::events_pending() || Gdk::events_pending()) {
			Gtk::main_iteration_do(true);
		}
	}
	
	static function getArrayValue($key,&$array) {
		if(is_array($array) && array_key_exists($key,$array)) {
			return $array[$key];
		} else {
			return false;
		}
	}
	
	static function mksnd($snd) {
		self::$sndsrc[self::$sndsrccur]->stop();
		self::$sndsrc[self::$sndsrccur]->buffer = null;
		self::$sndsrc[self::$sndsrccur]->buffer = self::$snd[$snd];
		self::$sndsrc[self::$sndsrccur]->play();
		
		self::$sndsrccur = !self::$sndsrccur;
	}

}

if(!is_dir(EXECROOT.lcars::UI_CACHE_DIR)) {
	mkdir(EXECROOT.lcars::UI_CACHE_DIR,0777,true);
} else {
	if(!is_writable(EXECROOT.lcars::UI_CACHE_DIR)) {
		die("enable to write to cache directory.\n");
	}
}

lcars::$forceRegen = true;

?>